﻿using System;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using Webdiver;

namespace AnyOffice.general.notify.show
{
    public partial class index1 : ModulePage
    {
        public void ChangePage(object src, PageChangedEventArgs e)
        {
            this.AspNetPager1.CurrentPageIndex = e.NewPageIndex;
            this.BindData();
        }
        public string GetNew(string readers)
        {
            readers = "," + readers + ",";
            if (readers.IndexOf("," + new UserCache().UserId + ",") < 0)
            {
                return "<img src=/images/new.gif align=absmiddle>";
            }
            return string.Empty;
        }
        public string GetUserNames(string userIds)
        {
            return StringHelper.GetUserNames(base.Conn, userIds);
        }
        private void BindData()
        {
            UserCache cache = new UserCache();
            DataTable table = new NotifyDao().SelectShowPaged(base.Conn, this.AspNetPager1.PageSize, this.AspNetPager1.CurrentPageIndex, false, cache.DeptId, cache.PrivId, base.User.Identity.Name, Convert.ToInt32(this.ViewState["TypeId"].ToString()));
            this.rptNotify.DataSource = table;
            this.rptNotify.DataBind();
            this.litNavCount.Text = "<span class=\"small1\">共&nbsp;<span class=\"big4\">" + this.AspNetPager1.RecordCount.ToString() + "</span>&nbsp;条公告通知";
            this.litNavPager.Text = "<span class=\"small1\">当前为第" + this.AspNetPager1.CurrentPageIndex.ToString() + "页，共" + this.AspNetPager1.PageCount.ToString() + "页，每页最多" + this.AspNetPager1.PageSize.ToString() + "条</span>";
            this.ViewState["CurrentPage"] = this.AspNetPager1.CurrentPageIndex.ToString();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                int typeId = (Request.QueryString["type_id"] != null) ? int.Parse(Request.QueryString["type_id"].ToString()) : 0;
                this.ViewState["TypeId"] = typeId;
                DataTable table = new NotifyTypeDao().SelectAll(base.Conn);
                this.ddlTypeId.DataSource = table;
                this.ddlTypeId.DataBind();
                this.ddlTypeId.Items.Insert(0, new ListItem("全部类型", "0"));
                this.ddlTypeId.Attributes.Add("onchange", "change_type(this.value);");
                if (this.ddlTypeId.Items.FindByValue(typeId.ToString()) != null)
                {
                    this.ddlTypeId.Items.FindByValue(typeId.ToString()).Selected = true;
                }
                this.AspNetPager1.PageSize = new ConfigManager().PageSize;
                UserCache cache = new UserCache();
                DataTable table2 = new NotifyDao().SelectShowPaged(base.Conn, this.AspNetPager1.PageSize, 1, true, cache.DeptId, cache.PrivId, base.User.Identity.Name, typeId);
                this.AspNetPager1.RecordCount = int.Parse(table2.Rows[0][0].ToString());
                this.BindData();
                if (this.AspNetPager1.RecordCount == 0)
                {
                    this.pnlMain.Visible = false;
                    this.litNavCount.Visible = false;
                    this.litNavPager.Visible = false;
                    this.litMessage.Text = base.ShowMessage("无公告通知");
                }
            }
        } 

    }
}
